<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
	<meta charset="utf-8" />
	<title>添加配送区域[{$detail.parent}]- {$Think.lang.cfg_website}</title>
	<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
	<meta content="" name="description" />
	<meta content="" name="author" />
	<!-- BEGIN GLOBAL MANDATORY STYLES -->
	<link href="{$NOW_THEME_URL}/Assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
	<link href="{$NOW_THEME_URL}/Assets/plugins/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" type="text/css"/>
	<link href="{$NOW_THEME_URL}/Assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
	<link href="{$NOW_THEME_URL}/Assets/css/style-metro.css" rel="stylesheet" type="text/css"/>
	<link href="{$NOW_THEME_URL}/Assets/css/style.css" rel="stylesheet" type="text/css"/>
	<link href="{$NOW_THEME_URL}/Assets/css/style-responsive.css" rel="stylesheet" type="text/css"/>
	<link href="{$NOW_THEME_URL}/Assets/css/themes/{:session('skin')}.css" rel="stylesheet" type="text/css" id="style_color"/>
	<!-- END GLOBAL MANDATORY STYLES -->
	<!-- BEGIN PAGE LEVEL STYLES -->
	<!-- END PAGE LEVEL STYLES -->
	<link rel="shortcut icon" href="favicon.ico" />
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="page-header-fixed">
	<!-- BEGIN HEADER -->
	<include file="Public:header" />
	<!-- END HEADER -->
	<!-- BEGIN CONTAINER -->
	<div class="page-container">
		<!-- BEGIN SIDEBAR -->
		<div class="page-sidebar nav-collapse collapse">
			<!-- BEGIN SIDEBAR MENU -->        
			<ul class="page-sidebar-menu">
            	<li>
					<!-- BEGIN SIDEBAR TOGGLER BUTTON -->
					<div class="sidebar-toggler hidden-phone"></div>
					<!-- BEGIN SIDEBAR TOGGLER BUTTON -->
				</li>
                {$menu_tree}
            </ul>
			<!-- END SIDEBAR MENU -->
		</div>
		<!-- END SIDEBAR -->
		<!-- BEGIN PAGE -->
		<div class="page-content">
			<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->
			<div id="portlet-config" class="modal hide">
				<div class="modal-header">
					<button data-dismiss="modal" class="close" type="button"></button>
					<h3>portlet Settings</h3>
				</div>
				<div class="modal-body">
					<p>Here will be a configuration form</p>
			  </div>
			</div>
			<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
			<!-- BEGIN PAGE CONTAINER-->
			<div class="container-fluid">
				<!-- BEGIN PAGE HEADER-->   
			  <div class="row-fluid">
					<div class="span12">
                    	<div class="clear">&nbsp;</div>                        
						<ul class="breadcrumb">
							<li>
								<i class="icon-home"></i>
								<a href="__APP__">{$Think.lang.cfg_page_home}</a> 
								<span class="icon-angle-right"></span>
							</li>
							<li>
								<a href="__URL__">配送方式管理</a>
								<span class="icon-angle-right"></span>
							</li>
							<li>
								<a href="__URL__/area_index/id/{$detail.shipid}">配送区域列表[{$detail.parent}]</a>
								<span class="icon-angle-right"></span>
							</li>
							<li>添加配送区域</li>
						</ul>
					</div>
				</div>
				<!-- END PAGE HEADER-->
				<!-- BEGIN PAGE CONTENT-->
				<div class="row-fluid">
					<div class="span12">
						<!-- BEGIN VALIDATION STATES-->
						<div class="portlet box purple">
							<div class="portlet-title">
								<div class="caption"><i class="icon-plus"></i>添加配送区域 [{$detail.parent}]</div>
								
								<div class="tools">
									<a href="javascript:;" class="collapse"></a>
								</div>
							</div>
							<div class="portlet-body form">
								<!-- BEGIN FORM-->
								<form action="__URL__/area_add" method="post" id="adcontentForm" class="form-horizontal form-bordered form-row-stripped">
									<input type="hidden" name="shipid" value="{$detail.shipid}" />
									<div class="alert alert-error hide">
										<button class="close" data-dismiss="alert"></button>
										{$Think.lang.cfg_form_err_allform}
									</div>
									<div class="alert alert-success hide">
										<button class="close" data-dismiss="alert"></button>
										{$Think.lang.cfg_form_ok_allform}
									</div>		
                      
                                    <div class="control-group">
										<label class="control-label">配送区域名称
										<span class="required">*</span>
										</label>
										<div class="controls">
                                          <input type="text" name="title" value="{$detail.title}" data-required="1" class="span6 m-wrap"/>
										</div>
									</div>
									
									 <div class="control-group">
										<label class="control-label">费用计算方式
                                        <span class="required">*</span></label>
										<div class="controls">
											<label class="radio">
											<div class="radio"><span>
                                            <input type="radio" onclick="showShipType('byWeight','byNumber')" value="byWeight" name="ship[type]" 
                                            checked />
                                            </span></div>按重量计算 
											</label>
											
                                            <label class="radio" style="width:200px">
											<div class="radio"><span>
											<input type="radio" onclick="showShipType('byNumber','byWeight')" value="byNumber" name="ship[type]"
                                             /></span>
                                             </div>按商品件数计算 
											</label>
										</div>
									</div>
									
									<div class="control-group byWeight"><!-- style="display:none" -->
										<label class="control-label">1KG以内费用
										<span class="required">*</span>
										</label>
										<div class="controls">
                                          <input type="text" name="ship[base_fee]" value="{$ship.base_fee}" data-required="1" class="span6 m-wrap"/>
										</div>
									</div>
									
									<div class="control-group byWeight" style="display:none">
										<label class="control-label">续重每千克的费用
										<span class="required">*</span>
										</label>
										<div class="controls">
                                          <input type="text" name="ship[step_fee]" value="{$ship.step_fee}" data-required="1" class="span6 m-wrap"/>
										</div>
									</div>
									
									<div class="control-group byNumber" style="display:none">
										<label class="control-label">单件商品费用
										<span class="required">*</span>
										</label>
										<div class="controls">
                                          <input type="text" name="ship[item_fee]" value="{$ship.item_fee}" data-required="1" class="span6 m-wrap"/>
										</div>
									</div>
									
									<div class="control-group">
										<label class="control-label">免费额度
										<span class="required">*</span>
										</label>
										<div class="controls">
                                          <input type="text" name="ship[free_money]" value="{$ship.free_money}" data-required="1" class="span6 m-wrap"/>
										</div>
									</div>
									
									<div class="control-group">
										<div id="ship_region" style="min-height:50px;border:1px solid #ccc;margin:5px;margin-left:180px; padding:10px;">
										<volist name="detail.regions" id="v">
										<input type="checkbox" checked id="chk{$v.areaid}" value="{$v.title}" name="regions[{$v.areaid}]" style="vertical-align:top">
	   			    					 {$v.title}&nbsp;&nbsp;&nbsp;&nbsp;
										</volist>
										</div>
										<div id="areaBox" style="margin-left:180px;display:inline;width:70%" ></div>
										<div  style="display:inline;vertical-align:top"><input type="button" value="+" id="btn_ship_add" style="width:40px;height:25px"/>
										</div>
									</div>
                                    
									<div class="form-actions">
										<button type="submit" class="btn purple">{$Think.lang.cfg_form_ele_submit}</button>
										<button type="reset" class="btn">{$Think.lang.cfg_form_ele_reset}</button>
									</div>
								</form>
								<!-- END FORM-->
							</div>
						</div>
						<!-- END VALIDATION STATES-->
					</div>
                    <!-- UploadPic STATES -->
                    <div class="modal hide fade uploadPic-modal" tabindex="-1" style="width:650px; height:420px;"></div>
                    <!-- UploadPic END -->
				</div>
				<!-- END PAGE CONTENT-->         
		  </div>
			<!-- END PAGE CONTAINER-->
		</div>
		<!-- END PAGE -->
	</div>
	<!-- END CONTAINER -->
	<!-- BEGIN FOOTER -->
	<include file="Public:footer" />
	<!-- END FOOTER -->
	<!-- BEGIN JAVASCRIPTS(Load javascripts at bottom, this will reduce page load time) -->
	<!-- BEGIN CORE PLUGINS -->
	<script src="__PUBLIC__/Js/jquery.min.js" type="text/javascript"></script>
	<script src="{$NOW_THEME_URL}/Assets/plugins/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>      
	<script src="{$NOW_THEME_URL}/Assets/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
	<!--[if lt IE 9]>
	<script src="{$NOW_THEME_URL}/Assets/plugins/excanvas.min.js"></script>
	<script src="{$NOW_THEME_URL}/Assets/plugins/respond.min.js"></script>  
	<![endif]-->  
	<script src="{$NOW_THEME_URL}/Assets/plugins/jquery.cookie.min.js" type="text/javascript"></script>
	<!-- END CORE PLUGINS -->
    
    <!-- BEGIN XHEDITOR -->
    <script type="text/javascript" src="{$NOW_THEME_URL}/Assets/plugins/xheditor/xheditor-1.2.1.min.js"></script>
    <script type="text/javascript" src="{$NOW_THEME_URL}/Assets/plugins/xheditor/xheditor_lang/{$Think.LANG_SET}.js"></script>
    <script type="text/javascript" src="{$NOW_THEME_URL}/Assets/plugins/artdialog/jquery.artdialog.js?skin=bootstrap"></script>
	<script type="text/javascript" src="{$NOW_THEME_URL}/Assets/plugins/artdialog/plugins/iframeTools.js"></script> 
	<script type="text/javascript" src="{$NOW_THEME_URL}/Assets/plugins/jquery-validation/dist/jquery.validate.min.js"></script>
    <script type="text/javascript" src="{$NOW_THEME_URL}/Assets/plugins/jquery-validation/localization/messages_{$Think.LANG_SET}.js"></script>
	<script src="{$NOW_THEME_URL}/Assets/scripts/app.js"></script>
	<script src="{$NOW_THEME_URL}/Assets/scripts/artonce/add.js"></script> 
    <script src="{$NOW_THEME_URL}/Assets/scripts/upload/pic.js"></script>
	<!-- END PAGE LEVEL STYLES -->    
	<script type="text/javascript">
	
		var ABS_URL_Theme = "{$NOW_THEME_URL}/";
		var ABS_URL       = "{$Think.TMPL_URL}/";
		var REL_URL       = "{$Think.REL_URL}";

		var vMessage = {};
		vMessage.title_required       = '{$Think.lang.em_form_validata_title_required}';
		vMessage.title_regex          = '{$Think.lang.em_form_validata_title_regex}';
		vMessage.keywords_required    = '{$Think.lang.em_form_validata_keywords_required}';
		vMessage.keywords_regex       = '{$Think.lang.em_form_validata_keywords_regex}';
		vMessage.description_required = '{$Think.lang.em_form_validata_description_required}';
		vMessage.description_regex    = '{$Think.lang.em_form_validata_description_regex}';
		
		var jsLang = {};
		jsLang.crop_title      = '{:L("cfg_upl_crop_title")}';
		jsLang.crop_false      = '{:L("cfg_upl_crop_false")}';
		jsLang.crop_noselect   = '{:L("cfg_upl_crop_noselect")}';
		jsLang.uploadSinglePic = '{:L("cfg_upl_thumbpic_btn")}';
		jsLang.uploadAtlasPic  = '{:L("cfg_upl_atlaspic_btn")}';
		jsLang.uploadScan      = '{:L("cfg_upl_scan")}';
		
		jQuery(document).ready(function() {   

		   App.init();
		   //adcontentForm.init();
		  
		   $('#btn_ship_add').live("click",function(){
			   var option = $('select[name="area"]>option:selected').filter(":last");
			   var value  = option.val();
			   var text   = option.text();
			   //alert(value+","+text);
			   var size   = $('#chk'+value).size();
			   if(size==0 && value!='0' && value){
				   var html   = $('#ship_region').html();
				   var append = '<input type="checkbox" checked id="chk'+value+'" value="'+text+'" name="regions['+value+']" style="vertical-align:top">'
	   			    			+text+'&nbsp;&nbsp;&nbsp;&nbsp;';
	  			  $('#ship_region').html(html+append);
			   }
		   });
		   
		   $('.byWeight').show();
		});
		
		function showShipType(obj1,obj2){
			$('.'+obj2).hide();
			$('.'+obj1).show();
		}
		
		var linkage_json = {$detail.json|json_encode} ;
  		$(function(){
			//初始值处理
			var did = '';
			if(did!=''){
				//var level = "";
				$('#areaBox').html(dealInitialarea(did,'',level));
			}else{
				$('#areaBox').html(showLinkagearea(39,2,0));
			}
			$('select[name="area"]').live('change',function(){
				var nowLevel = parseInt($(this).attr('level'));
				var nextLevel = nowLevel+1;
				//清除自此以后的select
				$('select[name="area"]').each(function(index, element) {
					if(parseInt($(this).attr('level'))>nowLevel){
						$(this).remove();
					}
				});
				//$('#ssxadd').val($('select[name="area"]').find("option:selected").text());
				//$('input[name="area'+nowLevel+'"]').val($(this).val());
				//显示下一个select
				$('#areaBox').append(showLinkagearea($(this).val(),nextLevel,0));
			});
			
			//处理初始值
			function dealInitialarea(lid,result,level){
				if(lid){
					$.each(linkage_json , function(i, n){
						if(lid==i){
							result = dealInitialarea(n[1],result,(parseInt(level)-1))+''+showLinkagearea(n[1],level,i);
							return false;
						}
					});
				}
				
				return result;
			}
			
			//响应select改变事件
			function showLinkagearea(pid,level,nid){
				var html = ''; //最终输出的HTML
				var have = false; //是否有子词典
				html += '<select name="area" size="15" id="area'+level+'" level="'+level+'" style="width:120px;margin:5px;">';
				html += '<option value="0">请选择</option>';
				$.each(linkage_json , function(i, n){
					if(pid==n[1]){
						if(nid==i){
							html += '<option value="'+i+'" selected>'+n[0]+'</option>';
						}else{
							html += '<option value="'+i+'">'+n[0]+'</option>';
						}
						have = true;
					}
				});
				html += '</select>';
				html += '<input type="hidden" name="area'+level+'" value="'+nid+'"/>';
				
				//没有子词典则此次输出为空
				if(!have){
					html = '';
				}
				return html;
			}
		});
	</script>
	<!-- END JAVASCRIPTS -->   
</body>
<!-- END BODY -->
</html>